package com.fy.service.impl;

import com.fy.dao.EpcDictDao;
import com.fy.entity.EpcDict;
import com.fy.entity.EpcUser;
import com.fy.entity.PageEntity;
import com.fy.service.EpcDictService;
import com.fy.utils.ObjectUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


@Service("epcDictService")
public class EpcDictServiceImpl implements EpcDictService {
    @Autowired
    private EpcDictDao epcDictDao;

    /***
     * <b>查询的分页</b>
     * @param record
     * @return
     */
    public List<EpcDict> getEpcDictListPage(EpcDict record, PageEntity page) {
        //List<EpcDict> epcDictList =this.queryForListPage(mapperName + ".getEpcDictListPage", record, page);
        PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
        List<EpcDict> epcDictList = epcDictDao.getEpcDictListPage(record);
        PageInfo<EpcDict> pageInfo = new PageInfo<>(epcDictList);
        page.setTotalResultSize((int)pageInfo.getTotal());
        return epcDictList;
    }

    /***
     * <b>添加</b>
     * @param record
     * @return
     */
    public Long editEpcDict(EpcDict record) throws Exception {
        if(ObjectUtils.isNotNull(record.getId())){
            return this.epcDictDao.updateEpcDictById(record);
        }else{
            return this.epcDictDao.addEpcDict(record);
        }
    }


    public Long editEpcDictByKey(EpcDict record) throws Exception {
        return this.epcDictDao.updateEpcDictByKey(record);
    }

    /**
     * 根据id查询
     * @param record
     * @return
     */
    public EpcDict getEpcDictById(EpcDict record){
        return  this.epcDictDao.getEpcDictById(record);
    }

    /**
    *批量删除
     */
    public void deleteEpcDictBatch(String ids) {
        Map<String,Object> dataMap = new HashedMap();
        dataMap.put("ids",ids);
        epcDictDao.deleteEpcDictBatch(dataMap);
    }

    public EpcDict getDictByKey(EpcDict dict) {
        return  epcDictDao.getEpcDictByKey(dict);
    }
}
